package com.rocketmq.test.provider;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

/**
 * @author hejianglong
 * @date 2019/12/6
 */
public class SyncProducer {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("group_120613");
        producer.setNamesrvAddr("192.168.50.140:9876");
        producer.start();

        for (int i = 0; i < 5; i++) {
            Message msg = new Message();
            msg.setTopic("TopicTest");
            msg.setTags("TagA");
            msg.setBody(("hello " + i).getBytes(RemotingHelper.DEFAULT_CHARSET));
            SendResult sendResult = producer.send(msg);
            System.out.printf("%s%n", sendResult);
        }
        producer.shutdown();
    }
}
